#include <iostream>
using namespace std;

int numsOfOne(int num) {
  int count = 0;
  while (num) {
    ++count;
    num = num & (num - 1);
  }
  return count;
}

int main() {
  cout << "num: 10 numsOfOne: " << numsOfOne(10) << " expected: 2" << endl;
  cout << "num: 0x8000000  numsOfOne: " << numsOfOne(0x8000000) << " expected: 1" << endl;
  return 0;
}
